<template>
  <!-- 搜索产品页 -->
  <div>
    <van-dropdown-menu>
      <van-dropdown-item :options="option1" title="综合" disabled />
      <van-dropdown-item
        v-model="value1"
        :options="option1"
        title="价格"
        @change="pirceChange"
      />
      <van-dropdown-item
        v-model="value2"
        :options="filterCategory"
        title="分类"
        @change="categoryChange"
      />
    </van-dropdown-menu>
    <!-- 产品列表 -->
    <!-- 产品为空时显示空状态 -->
    <van-empty
      v-if="goodslist.length == 0"
      description="对不起，没有这些产品"
    />
    <Products v-else :goodslist="goodslist" />
  </div>
</template>

<script>
import Products from "@/components/Products";
export default {
  props: ["goodslist", "filterCategory"],
  components: {
    Products,
  },
  methods: {
    categoryChange(value) {
      this.$emit("categoryChange", value);
    },
    pirceChange(value) {
      this.$emit("pirceChange", value);
    },
  },
  // 需求：正确地钩上分类中的某一项：要把value2做活了。value2的值必须为filterCategory这个数组中checked为true的这一项
  beforeUpdate() {
    this.filterCategory.map((item) => {
      if (item.checked) {
        this.value2 = item.value;
      }
    });
  },
  data() {
    return {
      value1: 0,
      value2: 1010000,
      option1: [
        { text: "价格由高到低", value: "desc" },
        { text: "价格由低到高", value: "asc" },
      ],
      // option2: [
      //   { text: "默认排序", value: "a" },
      //   { text: "好评排序", value: "b" },
      //   { text: "销量排序", value: "c" },
      // ],
    };
  },
};
</script>
 
<style lang = "less" scoped>
</style>